home *** CD-ROM | disk | FTP | other *** search
/ Night Owl - The Best of BBS / Night Owl The Best of BBS (NOP-BBS) (Night Owl Publisher) (1994).iso / 014a / ezbbs215.lha / Source / mail2eazy.c < prev    next >
C/C++ Source or Header  |  1994-02-06  |  3KB  |  125 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include <proto/dos.h>
  6. #include <proto/exec.h>
  7.  
  8.  
  9.  
  10. #define VERSION "1.2"
  11. static char *version = "\0$VER: mail2eazy "VERSION" ("__AMIGADATE__")";
  12.  
  13.  
  14.  
  15. void space2under(char *s)
  16. {
  17.   while (s && *s) {
  18.     if (*s==' ')
  19.       *s = '_';
  20.     s++;
  21.   }
  22. }
  23.  
  24.  
  25.  
  26. void kill_quotes(char *s)
  27. {
  28.   while (s && *s) {
  29.     if (*s=='\"')
  30.       *s = '\'';
  31.     s++;
  32.   }
  33. }
  34.  
  35.  
  36.  
  37. int main(int argc, char *argv[])
  38. {
  39.   if (argc==2) {
  40.     char tmp[80];
  41.     FILE *fp;
  42.  
  43.     sprintf(tmp,"%s%ld","MB_TMP:Mail2Eazy.tmp",(long)FindTask(NULL));
  44.  
  45.     if (fp=fopen(tmp,"w")) {
  46.       register int c = 0;
  47.       char username[256];
  48.       char uucpadr[256];
  49.       char *to_user = argv[1];
  50.       char subject[256];
  51.       char exec[256];
  52.       char str[1024];
  53.       BOOL ende = FALSE;
  54.  
  55.       strcpy(username,"unknown");
  56.       strcpy(subject,"none");
  57.       strcpy(uucpadr,"");
  58.  
  59.       while (!ende && fgets(str,1023,stdin)) {
  60.         if (strlen(str)==0 || strcmp(str,"\n")==0)
  61.           ende = TRUE;
  62.         else if ((strnicmp(str,"From: ",6)==0 && strlen(uucpadr)==0) || strnicmp(str,"Reply-To: ",10)==0) {
  63.           char *p;
  64.           char *str2;
  65.           str2 = strstr(str,": ")+2;
  66.  
  67.           strcpy(uucpadr,str2);
  68.           kill_quotes(uucpadr);
  69.           if (strchr(uucpadr,'\n'))
  70.             *strchr(uucpadr,'\n') = 0;
  71.  
  72. #if 0
  73.           strcpy(username,str2);
  74.           p = username;
  75.           while (*p && *p!='@') {
  76.             p++;
  77.           }
  78.           if (*p=='@')
  79.             *p = 0;
  80. #endif
  81.           if (p=strchr(str2,'@')) {
  82.             int pos;
  83.             for (pos=0,p--; p>=str2 && *p!=' ' && *p!='\t' && *p!='<'; p--)
  84.               username[pos++] = *p;
  85.             username[pos] = 0;
  86.             strrev(username);
  87.           }
  88.  
  89.           if (strchr(username,'\n'))
  90.             *strchr(username,'\n') = 0;
  91.           username[15] = 0;
  92.           kill_quotes(username);
  93.         }
  94.         else if (strncmp(str,"Subject: ",9)==0) {
  95.           strcpy(subject,str+9);
  96.           kill_quotes(subject);
  97.           if (strchr(subject,'\n'))
  98.             *strchr(subject,'\n') = 0;
  99.           subject[40] = 0;
  100.         }
  101.       }
  102.  
  103.       while ((c=fgetc(stdin))!=EOF) {
  104.         if (c=='\\')
  105.           fputc('\\',fp);
  106.         fputc(c,fp);
  107.       }
  108.       fprintf(fp,"\n");
  109.  
  110.       fclose(fp);
  111.  
  112.       sprintf(exec,"MB:C/ImportMail \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",username,to_user,uucpadr,subject,tmp);
  113.       System(exec,NULL);
  114.       DeleteFile(tmp);
  115.     }
  116.   }
  117.   else {
  118.     fprintf(stderr,"\033[1;33mEazyBBS\033[0m ⌐ 1988-1994 Andreas M. Kirchwitz\n"
  119.                    "Usage: mail2eazy \033[3m<to> \033[0m <text\n");
  120.   }
  121.  
  122.   exit(0);
  123. }
  124.  
  125.